const mongoose = require('mongoose')

const Schema = mongoose.Schema; // 设计数据库模型

// 连接数据库
mongoose.connect('mongodb://localhost/blog', {
  useNewUrlParser: true,
  useUnifiedTopology: true
});


// 标题  内容  分类   

const topicSchema = new Schema({
  kind: { // 分类
    type: String,
    required: true
  },
  title: { // 标题
    type: String,
    required: true
  },
  content: { // 内容
    type: String,
    required: true
  },
  nickname: { // 昵称
    type: String,
    required: true
  },
  author: { // 作者_id
    type: String,
    required: true
  },
  created_Date: { // 创建时间
    type: Date,
    default: new Date
  },
  watch: { // 观看数量
    type: Number,
    default: 0
  },
  messages: { // 评论
    type: Number,
    default: 0
  }
})



module.exports = mongoose.model('Topic', topicSchema);  